package com.xja.controller;

import com.xja.model.dto.CommentDTO;
import com.xja.model.vo.resp.CommentVO;
import com.xja.model.vo.resp.Result;
import com.xja.service.ICommentService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 文章评论表 前端控制器
 * </p>
 *
 * @author caijg
 
 */
@RestController
@RequestMapping("/user/comment")
@Tag(name = "文章评论模块")
@Slf4j
@RequiredArgsConstructor
public class CommentController {

    private final ICommentService commentService;

    @Operation(summary = "用户提交评论")
    @PostMapping()
    public Result<Void> submitComment(@RequestBody CommentDTO commentDTO) {
        log.info("用户提交评论:{}", commentDTO);
        commentService.submitComment(commentDTO);
        return Result.success();
    }

    @Operation(summary = "用户获取文章评论列表")
    @GetMapping("/{articleId}")
    public Result<List<CommentVO>> getComments(@PathVariable("articleId") Long articleId) {
        log.info("获取文章{}的评论", articleId);
        List<CommentVO> commentVOList = commentService.getArticleComments(articleId);
        return Result.success(commentVOList);
    }

    @Operation(summary = "用户点赞/取消点赞评论")
    @PostMapping("/like/{commentId}")
    public Result<Boolean> likeComment(@PathVariable("commentId") Long commentId) {
        log.info("用户点赞评论:{}", commentId);
        Boolean liked = commentService.likeComment(commentId);
        return Result.success(liked);
    }
}